package usersManagement.model;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import org.jboss.resteasy.annotations.LinkHeaderParam;

import javax.persistence.*;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

@Entity
@Table(name = "organization")
public class Organization implements Serializable {
// ------------------------------ FIELDS ------------------------------

    private static final long serialVersionUID = 3646102793177287948L;
    

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotEmpty
    private String name;

    @NotEmpty
    private String description;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name="organization_country",
            joinColumns=@JoinColumn(name="organization_id"),
            inverseJoinColumns=@JoinColumn(name="country_id"))
    private Set<Country> countriesOfOperation ;

// --------------------------- CONSTRUCTORS ---------------------------

    public Organization() {
        id = null ;
    }

    public Organization(String name, String description) {
        this.name = name;
        this.description = description;
    }

// --------------------- GETTER / SETTER METHODS ---------------------

    public Set<Country> getCountriesOfOperation() {
        return countriesOfOperation;
    }

    public void setCountriesOfOperation(Set<Country> countriesOfOperation) {
        this.countriesOfOperation = countriesOfOperation;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

// ------------------------ CANONICAL METHODS ------------------------

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Organization that = (Organization) o;

        if (!name.equals(that.name)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return name.hashCode();
    }

    @Override
    public String toString() {
        return "Organization{" +
                "description='" + description + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}